package com.myh.cc.coom.singer.viewmodel

import android.support.v7.widget.LinearLayoutManager
import android.widget.LinearLayout
import com.bumptech.glide.Glide
import com.myh.cc.base.BaseModel
import com.myh.cc.coom.singer.adapter.SingerDetailsAdapter
import com.myh.cc.coom.singer.bean.SingerDetailsBean
import com.myh.cc.coom.singer.net.SingerNetControl
import com.myh.cc.databinding.ActivitySingerDetailsBinding
import com.myh.cc.util.ConstantUtil

/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/16.   ：
 */
class SingerDetailsModel: BaseModel<ActivitySingerDetailsBinding,SingerNetControl>(){

    override fun onBeforeRequest(tag: Int) {

    }

    override fun onSuccess(data: Any, tag: Int) {
        initRecycleView(data as SingerDetailsBean)
    }

    override fun onError(errorMag: String, tag: Int) {

    }

    /**
     *  singermid：歌手mid。可从歌手列表里面获取
        begin：当前页
        num：每页歌曲数量
        format：数据格式
     */
    fun getDetails(singermid: String){

        var map = HashMap<String,String>()
        map.put("format","json")
        map.put("notice","0")
        map.put("platform","yqq")
        map.put("needNewCode","0")
        map.put("singermid",singermid)
        map.put("begin","0")
        map.put("num","30")
        map.put("songstatus","1")

        mControl.getDetails(this,"",map,ConstantUtil.requestTagOne)
    }


    fun initRecycleView(bean: SingerDetailsBean){

        val picUrl = "https://y.gtimg.cn/music/photo_new/T001R300x300M000"+bean.data.singer_mid+".jpg?max_age=2592000"

        Glide.with(getContext()).load(picUrl).into(mBinder.sdIvImg)

        mBinder.sdTvName.text = bean.data.singer_name

        mBinder.sdTvDesc.text = "歌曲共"+bean.data.total+"首"

        mBinder.sdDetialsTv.layoutManager = LinearLayoutManager(getContext(),LinearLayout.VERTICAL,false)
        mBinder.sdDetialsTv.adapter = SingerDetailsAdapter(bean)

    }


}